<?php

/*
 *
 * @authors : IT123编程社区-mastudy
 * @email  :admin@it123.org
 * @bbs http://www.it123.org
 *  @link http://www.it123.org
 *  @Powered By  ©2016 www.it123.org[IT123编程社区]
 */

// 本类由系统自动生成，仅供测试用途
class CommonAction extends Action {

        public function _initialize() {
                
        }

        public function index() {

                $this->display();
        }

        public function getGlinkArt($limit = 8) {



                $linkdb = M('glink');



                $where['link_verifystatus'] = 1;

                $lists = $linkdb->where($where)->order('link_visits desc')->limit($limit)->select();






                $lists = ToolsAction::resetGlinkList($lists);


                return $lists;
        }

        //============bloger start/

        public function getUserArticleList() {




                $uid = $this->_post('uid');


                $page = $this->_post('page');




                $page = isset($page) ? $page : 1; //当前页


                $pagesize = isset($pagesize) ? $pagesize : 10; //每页显示的数量



                $offset = ($page - 1) * $pagesize;


                //问答



                $articleDB = M('article');
                $where_article['article_author_id'] = $uid;
                $where_article['article_ispubish'] = 1;
                $where_article['article_verifystatus'] = 1;
                $where_article['article_show'] = 1;

                $article_lists = $articleDB->where($where_article)->order('article_addtime DESC')->limit($offset, $pagesize)->select();




                $article_lists = ToolsAction::resetArticleList($article_lists);




                if ($article_lists) {
                        echo json_encode($article_lists);
                } else {

                        echo json_encode(null);
                }
        }

        public function getUserAskList() {




                $uid = $this->_post('uid');


                $page = $this->_post('page');




                $page = isset($page) ? $page : 1; //当前页


                $pagesize = isset($pagesize) ? $pagesize : 10; //每页显示的数量



                $offset = ($page - 1) * $pagesize;


                //问答


                $askDB = M('ask');
                $where_ask['ask_author_id'] = $blogerinfo['member_id'];
                $where_ask['ask_ispubish'] = 1;
                $where_ask['ask_verifystatus'] = 1;
                $where_ask['ask_show'] = 1;

                $ask_lists = $askDB->where($where_ask)->order('ask_addtime DESC')->limit($offset, $pagesize)->select();




                $ask_lists = ToolsAction::resetAskList($ask_lists);




                if ($ask_lists) {
                        echo json_encode($ask_lists);
                } else {

                        echo json_encode(null);
                }
        }

        public function getUserTopicList() {




                $uid = $this->_post('uid');


                $page = $this->_post('page');




                $page = isset($page) ? $page : 1; //当前页


                $pagesize = isset($pagesize) ? $pagesize : 10; //每页显示的数量



                $offset = ($page - 1) * $pagesize;


                //问答




                $topicDB = M('group_topic');
                $where_topic['topic_author_id'] = $uid;

                $where_topic['topic_verifystatus'] = 1;


                $topic_lists = $topicDB->where($where_topic)->order('topic_time DESC')->limit($offset, $pagesize)->select();





                $topic_lists = ToolsAction::resetTopicList($topic_lists);




                if ($topic_lists) {
                        echo json_encode($topic_lists);
                } else {

                        echo json_encode(null);
                }
        }

        //============bloger  end /  

        public function getGlinkTagsList() {

                $tag = $this->_post('tag');


                $page = $this->_post('page');


                $page = isset($page) ? $page : 1; //当前页


                $pagesize = isset($pagesize) ? $pagesize : 10; //每页显示的数量



                $offset = ($page - 1) * $pagesize;


                //问答
                //    $topicdb = D('TagsTopicView');
                $db = M('glink');

                $where_glink['link_title|link_url'] = array('like', '%' . $tag . '%');

                $where_glink['link_verifystatus'] = 1;

                $link_lists = $db->where($where_glink)->order('link_visits desc')->group('link_id')->limit($offset, $pagesize)->select();


                $link_lists = ToolsAction::resetGlinkList($link_lists);




                if ($link_lists) {
                        echo json_encode($link_lists);
                } else {

                        echo json_encode(null);
                }
        }

        public function getTopicTagsList() {

                $tag = $this->_post('tag');


                $page = $this->_post('page');




                $page = isset($page) ? $page : 1; //当前页


                $pagesize = isset($pagesize) ? $pagesize : 10; //每页显示的数量



                $offset = ($page - 1) * $pagesize;


                //问答
                //    $topicdb = D('TagsTopicView');
                $topicdb = M('group_topic');

                $where_topic['topic_title|topic_desc'] = array('like', '%' . $tag . '%');


                // $where_ask['ask_title'] = array('like', '%' . $tag . '%');



                $where_topic['topic_verifystatus'] = 1;




                $topic_lists = $topicdb->where($where_topic)->order('topic_time desc')->group('topic_id')->limit($offset, $pagesize)->select();




                $topic_lists = ToolsAction::resetTopicList($topic_lists);










                if ($topic_lists) {
                        echo json_encode($topic_lists);
                } else {

                        echo json_encode(null);
                }
        }

        public function getArticleTagsList() {

                $tag = $this->_post('tag');


                $page = $this->_post('page');




                $page = isset($page) ? $page : 1; //当前页


                $pagesize = isset($pagesize) ? $pagesize : 10; //每页显示的数量



                $offset = ($page - 1) * $pagesize;


                //问答

                $articledb = D('TagsArticleView');


                $where_article['tags_item_title|article_title|article_desc|article_content'] = array('like', '%' . $tag . '%');

                $where_article['tags_module_id'] = 1;
                $where_article['article_verifystatus'] = 1;
                $where_article['article_ispubish'] = 1;
                $where_article['article_show'] = 1;



                $article_lists = $articledb->where($where_article)->order('article_addtime desc')->group('article_id')->limit($offset, $pagesize)->select();


                $article_lists = ToolsAction::resetArticleList($article_lists);





                if ($article_lists) {
                        echo json_encode($article_lists);
                } else {

                        echo json_encode(null);
                }
        }

        public function getAskTagsList() {

                $tag = $this->_post('tag');


                $page = $this->_post('page');




                $page = isset($page) ? $page : 1; //当前页


                $pagesize = isset($pagesize) ? $pagesize : 10; //每页显示的数量



                $offset = ($page - 1) * $pagesize;


                //问答

                $askdb = D('TagsAskView');


                $where_ask['tags_item_title|ask_title|ask_text'] = array('like', '%' . $tag . '%');

                // $where_ask['ask_title'] = array('like', '%' . $tag . '%');



                $where_ask['tags_module_id'] = 2;
                $where_ask['ask_verifystatus'] = 1;
                $where_ask['ask_ispublish'] = 1;
                $where_ask['ask_show'] = 1;



                $ask_lists = $askdb->where($where_ask)->order('ask_addtime desc')->group('ask_id')->limit($offset, $pagesize)->select();


                $ask_lists = ToolsAction::resetAskList($ask_lists);





                if ($ask_lists) {
                        echo json_encode($ask_lists);
                } else {

                        echo json_encode(null);
                }
        }

        public function getDonateList() {

                $donateDB = M('donate');


                $donateList = $donateDB->order('donate_sum desc')->select();

                return $donateList;
        }

        public function getHotHearten($limit = 5) {

                $heartenDB = M('hearten');


                $where['hearten_ispubish'] = 1;
                $where['hearten_verifystatus'] = 1;


                $List = $heartenDB->where($where)->order('hearten_time desc')->limit($limit)->select();

                $List = ToolsAction::resetheartenList($List);




                return $List;
        }

        public static function setRight($num = NULL) {


                if (!session('member_right')) {
                        session('member_right', $num);
                }





                self::checkRight();
        }

        public function getVolunteerList($numbers) {


                $vDB = D('MemberVolunteerView');
                $where['member_up_face'] = 1;



                $list = $vDB->where($where)->order('member_heat desc')->limit($numbers)->select();

                $list = ToolsAction::resetVolunteerList($list);

                //  $list = ToolsAction::myArraysort($list, 'member_hots', 'desc');



                return $list;
        }

        public function getMemberList($numbers = 10, $oder = 'member_heat desc') {


                $vDB = M('member_basic');
                $where['member_up_face'] = 1;
                $where['member_is_cancel'] = 0;



                $list = $vDB->where($where)->order($oder)->limit($numbers)->select();

                $list = ToolsAction::resetMemberList($list);

                //  $list = ToolsAction::myArraysort($list, 'member_hots', 'desc');


                return $list;
        }

        public function getMasterList($numbers) {


                $memerDB = M('member_basic');

                $where['member_accountstatus'] = 1;
                $where['member_up_face'] = 1;
                $where['member_nickname'] = array('NEQ', '');




                $list = $memerDB->where($where)->select();



                if ($list) {


                        foreach ($list as $k => $v) {

                                $list[$k]['articles'] = ToolsAction::getUserArticleInfo($list[$k]['member_id'], 'AllArticleCount');
                                //   $list[$k]['likes']=  ToolsAction::getUserLikes();

                                $list[$k]['asks'] = ToolsAction::getUserAskInfo($list[$k]['member_id']);

                                $list[$k]['answers'] = ToolsAction::getUserAnswerInfo($list[$k]['member_id']);
                                //   $list[$k]['likes']=  ToolsAction::getUserLikes();


                                $list[$k]['shares'] = ToolsAction::getUserSharenfo($list[$k]['member_id']);



                                $list[$k]['logins'] = ToolsAction::getUserLoginInfo($list[$k]['member_id']);



                                $list[$k]['article_visits'] = ToolsAction::getUserArticleInfo($list[$k]['member_id'], 'AllArticleVisitsCount');

                                $list[$k]['article_likes'] = ToolsAction::getUserAllLikesNO($list[$k]['member_id']);


                                $list[$k]['answer_good'] = ToolsAction::getUserAnswerInfo($list[$k]['member_id'], 'Allgood');

                                $list[$k]['master_face50'] = ToolsAction::getUserFace($list[$k]['member_id'], '32');


                                $list[$k]['hots'] = floor(( $list[$k]['shares']) * 1 + ($list[$k]['articles']) * 1 + ($list[$k]['article_visits']) / 50 + ($list[$k]['asks']) * 1 + ($list[$k]['answers']) * 1 + ($list[$k]['answer_good']) * 2 + ($list[$k]['logins']) / 3);






                                // $list[$k]['hots']=  ToolsAction::getUserAlllikesNO($list[$k]['member_id']);
                                // ToolsAction::getArticlelikesNO($data[$k]['article_id']);
                        }
                }



                $list = ToolsAction::myArraysort($list, 'hots', 'desc');

                $list = array_slice($list, 0, $numbers);

                return $list;
        }

        public static function checkRight() {





                if (session('member.member_type') > session('member_right')) {


                        $this->error('您的权限不能查看当前内容');

                        die();
                }
        }

        public function getCateTree() {



                $cateDB = M('cate');


                $where['cate_ispublish'] = 1;
                $catelist = $cateDB->where($where)->limit(30)->select();

                $catelist = ToolsAction::sortOut($catelist);

                if ($catelist) {

                        foreach ($catelist as $k => $v) {

                                $catelist[$k]['article_numbers'] = ToolsAction::getCateArticleNumbers($catelist[$k]['cate_id']);
                        }
                }



                return $catelist;
        }

        public static function getlikeNumber($module_id = NULL, $item_id = NULL) {







                if ($module_id == NULL) {
                        return FALSE;
                }


                $lDB = M('like');

                $where['like_module_id'] = $module_id;

                $where['like_item_id'] = $item_id;





                $num = $lDB->where($where)->count();


                return $num + 100;
        }

        public function recList() {

                $artDB = M('article');

                $where['article_rec'] = 1;
                $where['article_ispubish'] = 1;
                $where['article_verifystatus'] = 1;



                $reclist = $artDB->where($where)->order('article_visits desc')->select();


                $reclist = ToolsAction::resetArticleList($reclist);











                return $reclist;
        }

        public function hotTags() {

                $tags = M('tags');
                $field = array('tags_item_title', 'count(*)' => 'tag_count');
                $order = 'tag_count desc';


                $hottags = $tags->field($field)->group('tags_item_title')->order($order)->limit(40)->select();





                return $hottags;
        }

        public function getNewShare($limit = 5, $order = 'share_addtime DESC') {

                return $this->getHotShare($limit, $order);
        }

        public function getHotShare($limit = 5, $order = 'share_visits DESC') {






                $shareDB = M('share');

                $where['share_verifystatus'] = 1;
                $where['share_ispubish'] = 1;
                $where['share_show'] = 1;
                $data = $shareDB->where($where)->order($order)->limit($limit)->select();


                if ($data) {

                        foreach ($data as $k => $v) {



                                $data[$k]['share_addtime'] = date('Y-m-d', $data[$k]['share_addtime']);



                                $data[$k]['share_title'] = htmlspecialchars_decode($data[$k]['share_title']);
                        }
                }




                return $data;
        }

        public function getNewAsk($limit = 5, $order = 'ask_addtime DESC') {
                return $this->getHotAsk($limit, $order);
        }

        public function getHotAnswer($limit = 5, $order = 'answer_likes DESC') {






                $answerDB = M('ask_answer');

                $where['answer_verifystatus'] = 1;
                $where['answer_ispubish'] = 1;

                $data = $answerDB->where($where)->order($order)->limit($limit)->select();


                if ($data) {

                        foreach ($data as $k => $v) {



                                $data[$k]['answer_addtime'] = date('Y-m-d', $data[$k]['answer_addtime']);



                                $data[$k]['answer_title'] = htmlspecialchars_decode($data[$k]['answer_title']);
                        }
                }




                return $data;
        }

        public function getHotAsk($limit = 5, $order = 'ask_answers DESC') {



                $askDB = M('ask');

                $where['ask_verifystatus'] = 1;
                $where['ask_ispubish'] = 1;
                $where['ask_show'] = 1;
                $data = $askDB->where($where)->order($order)->limit($limit)->select();



                $data = ToolsAction::resetAskList($data);






                return $data;
        }

        public function getNewArt($limit = 8, $order = 'article_addtime DESC') {
                return $this->getHotArt($limit, $order);
        }

        //热门话题
        public function getHotTopic($limit = 8, $order = 'topic_likes DESC') {





                $topicDB = M('group_topic');

                $where['topic_verifystatus'] = 1;


                $data = $topicDB->where($where)->order($order)->limit($limit)->select();


                $data = ToolsAction::resetTopicList($data);





                return $data;
        }

        //热门文章
        public function getArtlist($limit = 8, $order = 'article_visits DESC') {





                $aDB = M('article');

                $where['article_verifystatus'] = 1;
                $where['article_ispubish'] = 1;
                $where['article_title'] = array('not in', '');
                $data = $aDB->where($where)->order($order)->limit($limit)->select();


                $data = ToolsAction::resetArticleList($data);



                return $data;
        }

        public function getSiteindexinfo() {

                //###########通用#######
                //搜索引擎
                $this->assign('searchsite_list', $this->getList('searchsite'));


                //商城购物

                $this->assign('shopsite_list', $this->getList('shopsite'));



                //直播门户

                $this->assign('videolive_list', $this->getList('videolive'));


                //新闻门户

                $this->assign('newssite_list', $this->getList('newssite'));


                //游戏门户

                $this->assign('gamesite_list', $this->getList('gamesite'));


                //视频门户

                $this->assign('videosite_list', $this->getList('videosite'));

                //视频门户

                $this->assign('emailsite_list', $this->getList('emailsite'));

                //旅游网站


                $this->assign('tourismsite_list', $this->getList('tourismsite'));


                //体育网站


                $this->assign('sportssite_list', $this->getList('sportssite'));


                //房产网站


                $this->assign('housesite_list', $this->getList('housesite'));





                //房产网站


                $this->assign('friendsite_list', $this->getList('friendsite'));




                $this->assign('musicsite_list', $this->getList('musicsite'));
                //小说门户

                $this->assign('novelsite_list', $this->getList('novelsite'));


                //军事门户
                $this->assign('militarysites_list', $this->getList('militarysites'));



                //健康门户
                $this->assign('healthsite_list', $this->getList('healthsite'));


                //健康门户
                $this->assign('expresssite_list', $this->getList('expresssite'));














                //###########it导航#######  
                //php框架

                $this->assign('phpframe_list', $this->getList('phpframe'));



                //java框架

                $this->assign('javaframe_list', $this->getList('javaframe'));


                //js框架

                $this->assign('jsframe_list', $this->getList('jsframe'));

                //移动端框架

                $this->assign('moveframe_list', $this->getList('moveframe'));

                //前端框架




                $this->assign('frontframe_list', $this->getList('frontframe'));
                //移动开发





                $this->assign('mobiledevelo_list', $this->getList('mobiledevelo'));

                // js插件

                $this->assign('jsplug_list', $this->getList('jsplug'));

                // api

                $this->assign('api_list', $this->getList('api'));

                //cms
                $this->assign('opencms_list', $this->getList('opencms'));


                //ide开发工具

                $this->assign('idetools_list', $this->getList('idetools'));



                //产品
                $this->assign('product_list', $this->getList('product'));


                //代码托管
                $this->assign('codehost_list', $this->getList('codehost'));




                //主机
                $this->assign('host_list', $this->getList('host'));

                // 开放平台

                $this->assign('open_list', $this->getList('open'));






                //移动应用

                $this->assign('mobileapps_list', $this->getList('mobileapps'));




                //源码收集

                $this->assign('sourcecode_list', $this->getList('sourcecode'));





                //团队协作

                $this->assign('teamwork_list', $this->getList('teamwork'));




                //在线教育

                $this->assign('edu_list', $this->getList('edu'));


                //在线教育

                $this->assign('itjob_list', $this->getList('itjob'));








                //站长工具

                $this->assign('webtools_list', $this->getList('webtools'));





                //广告联盟

                $this->assign('union_list', $this->getList('union'));
        }

        public function getList($tag, $limit = 20, $order = 'site_visits desc') {

                $siteDB = M('site');

                //在线教育
                $where['site_tag'] = $tag;


                $where['site_verifystatus'] = '1';

                $lists = $siteDB->where($where)->order($order)->limit($limit)->select();


                return $lists;
        }

}
